<?php

/**
 * @author thihien
 * @copyright 2011
 */

include_once('includes/general.php');
if(!tep_db_checkDb()) die('connect fail!');
$maloaihoptac=$_GET['maloaihoptac'];
$sql='SELECT count(id) as count FROM `tbl_hop_tac` where ma_loai_hop_tac='.$maloaihoptac ;
$kq=tep_db_query($sql);
$item1=tep_db_fetch_array($kq);
//bat dau viet phan trang
$display=5;// so san pham xuat hien tren mot trang
$record=$item1['count'];//tong so san pham
if($record>$display){
    $page=ceil($record/$display);
}
else{
    $page=1;
}
$start=isset($_GET['start']) && (int)$_GET['start']?$_GET['start']:0;

$content='';
$sql4='select * from tbl_hop_tac where ma_loai_hop_tac='.$maloaihoptac.' limit '.$start.', '.$display.'';
$kq4=tep_db_query($sql4);
/*-------------lay ten danh muc donvi nghien cuu*/
$sql2='select ten_loai_hop_tac from tbl_loai_hop_tac where id='.$maloaihoptac.' ';
$kq2=tep_db_query($sql2);
$item2=tep_db_fetch_array($kq2);
$content.='<div id="center">
             <div class="tin_tuc_noi_bat">
                <div class="tieude_center" id="tieude_donvi_center"><h3>'.$item2['ten_loai_hop_tac'].'</h3></div>';
    
    while($item=tep_db_fetch_array($kq4)){
         $content.='
         <div class="hienthi_tt">
                <div class="hinh_anh_dich_vu"><a href="?page=hoptac&mahoptac='.$item['id'].'&maloaihoptac='.$item['ma_loai_hop_tac'].'&mode=detail"><img  width="140" height="140" src="admincp/upload/'.$item['hinh_anh'].'"/></a></div>
                <div class="mo_ta_ngan_gon_dich_vu">'.$item['tom_tat'].'<br/>
                    <a href="?page=hoptac&mahoptac='.$item['id'].'&maloaihoptac='.$item['ma_loai_hop_tac'].'&mode=detail"><p>Chi Tiết...</p></a>
                </div>
           
        </div>';
   
    }
    $content.=' 
    <ul class="phantrang" id="phantrang1">';
         $content.='Trang:';
            if($page>1){
                $next=$start+$display;
                $prev=$start-$display;
                $current=($start/$display)+1;
                //hien thi phan trang prev
               
                if($current!=1){
                   $content.='<li><a href="?maloaihoptac='.$maloaihoptac.'&start='.$prev.'">Previous</a></li>'; 
                }
                 //hien thi trang
                 for($i=1;$i<=$page;$i++){
                   if($current!=$i){
                        $content.='<li><a href="?maloaihoptac='.$maloaihoptac.'&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    } 
                    else
                    {
                       $content.='<li class="current"><a href="maloaihoptac='.$maloaihoptac.'&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    }
                     
                 }
                //hien thi next
                if($current!=$page){
                    $content.='<li><a href="?maloaihoptac='.$maloaihoptac.'&start='.$next.'">Next</a></li>';  
                }
            }
            else{
                $content.='<li class="current" ><a href="?maloaihoptac='.$maloaihoptac.'&start='.$page.'">'.$page.'</a></li>';  
            }
       $content.=' </ul>
       </div> </div>
    ';  
   
if(isset($_GET['mode']) && $_GET['mode']=='detail'){
    $mahoptac=$_GET['mahoptac'];
    $maloaihoptac=$_GET['maloaihoptac'];
    $sql='select * from tbl_hop_tac where id='.$mahoptac;
    $kq=tep_db_query($sql);
    $item=tep_db_fetch_array($kq);
    $sql2='select ten_loai_hop_tac from tbl_loai_hop_tac where id='.$maloaihoptac.' ';
    $kq2=tep_db_query($sql2);
    $item2=tep_db_fetch_array($kq2);
    $content='
        <div id="center">
       
            <div class="tin_tuc_noi_bat">
                <div class="tieude_center" id="tieude_donvi_center"><h3>'.$item2['ten_loai_hop_tac'].'</h3></div>
                <div class="hienthi_tt1">
                    <div class="noidung_cb">'.$item['noi_dung'].'</div>
                </div>';
                
        
   $content.='</div>
     </div>
    ';  
}

echo $content;


?>